﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.Project;
using Jzy.Model.Project;
using Frame.Lib.Utilities;
using Frame.Lib.Common;


public partial class Project_Schedule_Edit : PageEdit
{
    private string TaskID
    {
        get
        {
            return Request["TaskID"];
        }
    }
    private string PrjID
    {
        get
        {
            return Request["PrjID"];
        }
    }

    TaskScheduleBO _schedule ;
    protected void Page_Load(object sender, EventArgs e)
    {
        _schedule = new TaskScheduleBO(TaskID);
        if (!IsPostBack)
        {
            PrjTaskBO task = new PrjTaskBO(int.Parse(PrjID));
            PrjTaskInfo info = task.GetInfo(TaskID);
            lblTaskName.Text = info.Name;
            txtPercent.Text = info.Percent.ToString();
            lblTimeLimit.Text = info.TimeLimit.ToString();
            lblWorkload.Text = info.Workload.ToString();

            string lastID = _schedule.GetLastID();
            if (lastID != null)
            {
                TaskScheduleInfo schInfo = _schedule.GetInfo(lastID);
                lblLastUpdateTime.Text = schInfo.InputTime.ToString("yyyy-MM-dd");
            }
            else
            {
                lblLastUpdateTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }

            if (task.HasChild(int.Parse(TaskID)))
            {
                txtPercent.Enabled = false;
                txtWorkload.Enabled = false;

                txtPercent.ToolTip = txtWorkload.ToolTip = "由于有子任务，该项不可修改";
                txtPercent.Style.Add("background-color", "#eeeeee");
                txtWorkload.Style.Add("background-color", "#eeeeee");
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (txtPercent.Text.Trim() == "")
            txtPercent.Text = "0";
        if (txtWorkload.Text.Trim() == "")
            txtWorkload.Text = "0";

        //更新任务的一些信息
        PrjTaskBO task = new PrjTaskBO(int.Parse(PrjID));
        PrjTaskInfo taskInfo = task.GetInfo(TaskID);
        taskInfo.Percent = int.Parse(txtPercent.Text);
        taskInfo.Workload += int.Parse(txtWorkload.Text);
        task.Save(taskInfo);

        //更新进度表
        TaskScheduleInfo info = new TaskScheduleInfo();
        info.InputTime = DateTime.Now;
        info.Remark = txtRemark.Text;
        info.TaskID = int.Parse(TaskID);
        info.UserID = AppSession.UserID;
        info.UserName = AppSession.UserName;
        info.Percent = taskInfo.Percent;
        info.Workload = taskInfo.Workload;       

        _schedule.Save(info);


        JSUtil.RefreshView();
        //string script = "top.frames['frameMain'].setProgress('" + TaskID + "'," + taskInfo.Percent + ");top.setTimeout(\"alert('添加进展成功')\",100);" + JSUtil.GetDelFrmString();
        //JSUtil.ResponseJS(script);
        
    }
}
